home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / !runtime / reverse.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  2.8 KB  |  55 lines  |  [TEXT/R*ch]

  1. /* Swap byte-order in 16-bit, 32-bit and 64-bit words */
  2.  
  3. #ifndef _reverse_
  4. #define _reverse_
  5.  
  6.  
  7. #define Reverse_short(s) {                                                    \
  8.   char * _p;                                                                  \
  9.   int _a;                                                                     \
  10.   _p = (char *) (s);                                                          \
  11.   _a = _p[0];                                                                 \
  12.   _p[0] = _p[1];                                                              \
  13.   _p[1] = _a;                                                                 \
  14. }
  15.  
  16. #define Reverse_int32(w) {                                                    \
  17.   char * _p;                                                                  \
  18.   int _a;                                                                     \
  19.   _p = (char *) (w);                                                          \
  20.   _a = _p[0];                                                                 \
  21.   _p[0] = _p[3];                                                              \
  22.   _p[3] = _a;                                                                 \
  23.   _a = _p[1];                                                                 \
  24.   _p[1] = _p[2];                                                              \
  25.   _p[2] = _a;                                                                 \
  26. }
  27.  
  28. #define Reverse_int64(d) {                                                    \
  29.   char * _p;                                                                  \
  30.   int _a;                                                                     \
  31.   _p = (char *) (d);                                                          \
  32.   _a = _p[0];                                                                 \
  33.   _p[0] = _p[7];                                                              \
  34.   _p[7] = _a;                                                                 \
  35.   _a = _p[1];                                                                 \
  36.   _p[1] = _p[6];                                                              \
  37.   _p[6] = _a;                                                                 \
  38.   _a = _p[2];                                                                 \
  39.   _p[2] = _p[5];                                                              \
  40.   _p[5] = _a;                                                                 \
  41.   _a = _p[3];                                                                 \
  42.   _p[3] = _p[4];                                                              \
  43.   _p[4] = _a;                                                                 \
  44. }
  45.  
  46. #ifdef SIXTYFOUR
  47. #define Reverse_word Reverse_int64
  48. #else
  49. #define Reverse_word Reverse_int32
  50. #endif
  51.  
  52. #define Reverse_double Reverse_int64
  53.  
  54. #endif /* _reverse_ */
  55.